Skip to content

Comments

feat: Preserve pointer types in generic iterators#409

Merged
kodiakhq[bot] merged 1 commit intomainfrom
fix/pointer-return-types
Feb 17, 2026
Merged

feat: Preserve pointer types in generic iterators#409
kodiakhq[bot] merged 1 commit intomainfrom
fix/pointer-return-types

Conversation

@murarustefaan
Copy link
Member

@murarustefaan murarustefaan commented Feb 17, 2026

Release-As: v0.4.0

@murarustefaan murarustefaan requested a review from a team as a code owner February 17, 2026 15:38
@murarustefaan murarustefaan requested review from Copilot and erezrokah and removed request for a team February 17, 2026 15:38
@murarustefaan murarustefaan added the automerge Add to automerge PRs once requirements are met label Feb 17, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the generic type normalization logic to properly preserve pointer types in generic iterators, specifically addressing the need to handle types like iter.Seq2[*github.Artifact, error] where pointer prefixes must be maintained.

Changes:

  • Refactored normalizedGenericTypeName to handle multiple type parameters and extract pointer handling into a separate helper function
  • Added normalizeFullTypeName helper function to normalize individual type names while preserving pointer prefixes
  • Added comprehensive unit tests covering various generic type scenarios including pointers, multiple type parameters, and versioned imports

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
interfaces/generate.go Refactored type normalization logic by extracting pointer handling into normalizeFullTypeName and updating normalizedGenericTypeName to support multiple type parameters
interfaces/generate_test.go Added comprehensive unit tests for normalizedGenericTypeName covering single/multiple type parameters, pointer types, and versioned imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

typeName = typeName[1:]
}

versionPattern := regexp.MustCompile(`/v\d+\.`)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is compiled on every function call. Since this function may be called multiple times during code generation (once per type parameter), consider moving the regex compilation to a package-level variable to improve performance. For example, declare var versionPattern = regexp.MustCompile(\/v\d+\.`)` at the package level and reuse it in this function.

Copilot uses AI. Check for mistakes.
// Generic output types have the full import path in the string value, so we need to normalize it
pattern := regexp.MustCompile(`\[(.*?)\]`)
groups := pattern.FindStringSubmatch((str))
pattern := regexp.MustCompile(`\[(.*)\]`)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is compiled on every function call. Since this function is called for each return type in method signatures, consider moving the regex compilation to a package-level variable to improve performance. For example, declare var genericTypePattern = regexp.MustCompile(\\[(.*)\]`)` at the package level and reuse it in this function.

Copilot uses AI. Check for mistakes.
Comment on lines +170 to +172
if versionPattern.MatchString(typeName) {
// Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse
importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1]
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential index out of bounds error. The code assumes that when versionPattern matches, parts[len(parts)-1] (the last path segment) will contain a dot and can be safely split to access index [1]. While this is true for well-formed versioned import paths like armappconfiguration/v2.ConfigurationStoresClientListResponse, malformed input could cause a panic. Consider adding a bounds check or using a more defensive approach, such as checking the length of the split result before accessing index [1].

Suggested change
if versionPattern.MatchString(typeName) {
// Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse
importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1]
if versionPattern.MatchString(typeName) && len(parts) >= 2 {
// Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse
lastParts := strings.Split(parts[len(parts)-1], ".")
if len(lastParts) >= 2 {
importName = parts[len(parts)-2] + "." + lastParts[1]
}

Copilot uses AI. Check for mistakes.
@kodiakhq kodiakhq bot merged commit d4fe386 into main Feb 17, 2026
15 checks passed
@kodiakhq kodiakhq bot deleted the fix/pointer-return-types branch February 17, 2026 15:50
kodiakhq bot pushed a commit that referenced this pull request Feb 17, 2026
🤖 I have created a release *beep* *boop*
---


## [0.3.37](v0.3.36...v0.3.37) (2026-02-17)


### Features

* Preserve pointer types in generic iterators ([#409](#409)) ([d4fe386](d4fe386))


### Bug Fixes

* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.2 ([#407](#407)) ([41c4bc3](41c4bc3))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Add to automerge PRs once requirements are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants